package codeRandomThoughts.Test1704判断字符串的两半是否相似;

public class Solution {
    public boolean halvesAreAlike(String s) {
        char[] charArray = s.toCharArray();
        int mid = charArray.length / 2;
        if (getVowelCount(charArray, 0, mid) == getVowelCount(charArray, mid, charArray.length)) {
            return true;
        } else {
            return false;
        }
    }

    //左闭右开
    public int getVowelCount(char[] chars, int begin, int end) {
        int count = 0;
        for (int i = begin; i < end; i++) {
            if (chars[i] == 'a' || chars[i] == 'e' || chars[i] == 'i' || chars[i] == 'o' || chars[i] == 'u' || chars[i] == 'A' || chars[i] == 'E' || chars[i] == 'I' || chars[i] == 'O' || chars[i] == 'U') {
                count++;
            }
        }
        return count;
    }
}
